using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Globalization;
using IPConfigLibrary;

namespace IPConfig32
{
    public partial class Controller
    {
        #region Members
        private MainView _MainView;
        #endregion

        #region Methods
        private void MainView_Show()
        {
            // Instantiate an instance
            this._MainView = new MainView();

            this._MainView.buttonRefresh.Click += 
                new EventHandler(MainView_buttonRefresh_Click);
            this._MainView.buttonRelease.Click += 
                new EventHandler(MainView_buttonRelease_Click);
            this._MainView.buttonRenew.Click += 
                new EventHandler(MainView_buttonRenew_Click);
            this._MainView.buttonExit.Click += 
                new EventHandler(MainView_buttonExit_Click);

            // Attach the MainView to the Application Context
            this._AppContext.MainForm = this._MainView;

            // Show the form
            this._MainView.Show();

            this._MainView.buttonRefresh.PerformClick();
        }

        #region Event Handlers
        private void MainView_buttonRefresh_Click(
            object sender, 
            EventArgs e)
        {
            Application.DoEvents();

            this._MainView.Cursor = Cursors.WaitCursor;

            IPConfig theIPConfig = IPConfig.Initialise();

            this._MainView.IPConfig.DataSource = theIPConfig;
            this._MainView.Adaptors.DataSource = theIPConfig.Adaptors;

            this._MainView.Cursor = Cursors.Default;
        }

        private void MainView_buttonRelease_Click(
            object sender,
            EventArgs e)
        {
            Application.DoEvents();

            this._MainView.Cursor = Cursors.WaitCursor;

            IPConfig theIPConfig = IPConfig.Release();

            this._MainView.IPConfig.DataSource = theIPConfig;
            this._MainView.Adaptors.DataSource = theIPConfig.Adaptors;

            this._MainView.Cursor = Cursors.Default;
        }

        private void MainView_buttonRenew_Click(
            object sender,
            EventArgs e)
        {
            Application.DoEvents();

            this._MainView.Cursor = Cursors.WaitCursor;

            IPConfig theIPConfig = IPConfig.Renew();

            this._MainView.IPConfig.DataSource = theIPConfig;
            this._MainView.Adaptors.DataSource = theIPConfig.Adaptors;

            this._MainView.Cursor = Cursors.Default;
        }

        private void MainView_buttonExit_Click(
            object sender, 
            EventArgs e)
        {
            Application.DoEvents();

            Application.Exit();
        }
        #endregion
        #endregion
    }
}
